stage.set_background("halfcourt")
sprite = codesters.Sprite("player1")
sprite.go_to(-175, -150)
net = codesters.Sprite("basketballnet")
net.go_to(215, 175)
stage.set_gravity(10)
sprite.set_gravity_off()
def click(sprite):
ball = codesters.Sprite("basketball")
ball.go_to(-175, -125)
ball.set_x_speed(10)
ball.set_y_speed(10)
# add other actions...
sprite.event_click(click)
stage.disable_right_wall()
def collision(net, hit_sprite):
my_var = hit_sprite.get_image_name()
if my_var == "basketball":
sprite.say("Score!")
hit_sprite.hide()
# add any other actions...
net.event_collision(collision)
t = codesters.Teacher()
text_sprites = t.find_function("Text")
try:
tval1 = stage.get_image_name()
except:
tval1 = "DNE"
try:
tval2 = sprite.get_image_name()
except:
tval2 = "DNE"
tval3 = len(text_sprites)
t1 = TestObjective()
t1.add_success(tval1 != "halfcourt", "Great job!")
t1.add_failure(tval1 == "halfcourt", "Did you change your background image?")
t2 = TestObjective()
t2.add_success(tval2 != "player1", "Great job!")
t2.add_failure(tval2 == "player1", "Did you change the image of your sprite?")
t3 = TestObjective()
t3.add_success(tval3 > 0, "Great job!")
t3.add_failure(tval3 == 0, "Did you add in a text sprite that provides the user with instructions?")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)